/*
 * Created on Oct 13, 2005 8:03:57 AM
 * 
 * $Id: UnixFileDesc.java,v 1.1 2005/10/16 14:14:58 olu Exp $
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package tripleo.framework.fs;

import tripleo.fs.File;

final class UnixFileDesc implements FileDesc {

	private String mPath;

	public UnixFileDesc(String aS) {
		mPath = aS;
	}

	public WriteHandle openWrite(int mode) throws FileOpFailure {
		if ((mode & Modes.FailIfExist) == 1) // TODO
			if (exists()) throw new FileOpFailure("EXISTS");
		UnixWriteHandle handle = new UnixWriteHandle(this);
//		if (mode & Modes.CreateAlways)
//			handle.truncate();
		return handle;
	}

	public boolean exists() {
		return backing().exists();
	}

	public ReadHandle openRead() {
		return new UnixReadHandle();
	}

	public String getPath() {
		return mPath;
	}

	public void unlink() throws FileOpFailure {
		if (!backing().delete())
			throw new FileOpFailure("java failed to delte directory");
	}

	private File backing() {
		return new tripleo.fs.File(getPath());
	}

	public String name() {
		return mPath;
	}

	public void create() throws FileOpFailure {
		new tripleo.fs.File(getPath()).mkdirs();
		
	}

	public void move(FileDesc fd2) throws FileOpFailure {
		new tripleo.fs.File(getPath()).renameTo(
				new tripleo.fs.File(fd2.name()));
		
	}

//	public void setPath(String aPath) {
//		mPath = aPath;
//	}
}
